package com.taptech.doufu.ui.activity;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextPaint;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.taptech.doufu.R;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity;
import com.taptech.doufu.util.TToast;
import com.taptech.doufu.util.sp.DiaoBaoSharedPreferences;

@SuppressLint("NewApi")
public class AboutUsActivity extends DiaobaoBaseActivity {

	private TextView titleTextView;
	private TextView mOfficeHeaderTextView;
	private TextView mOfficeContentTextView;
	private TextView mWeChatHeaderTextView;
	private TextView mWeChatContentTextView;
	private TextView mWeiBoHeaderTextView;
	private TextView mWeiBoContentTextView,mWeiBoContentTextView_two;
	private TextView mPhoneHeaderTextView;
	private TextView mPhoneContentTextView;
	private TextView mEmailHeaderTextView;
	private TextView mEmailContentTextView;
	private int clickCount;
	private long clickTime;
	private View layWebTest;
	private EditText etWebTest;
	private View btnWebTest;
	private LinearLayout mLlWeb;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about_us);

		titleTextView = (TextView) findViewById(R.id.activity_top_item_title);
		layWebTest = findViewById(R.id.layWebTest);
		boolean isOpenWebTest = DiaoBaoSharedPreferences.getSharedPreferencesValueToBoolean("WEB_TEST_KEY", this, false);
		if (isOpenWebTest) {
			layWebTest.setVisibility(View.VISIBLE);
		}
		etWebTest = (EditText) findViewById(R.id.etWebTest);
		btnWebTest = findViewById(R.id.btnWebTest);
		btnWebTest.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (etWebTest.getText().toString().isEmpty()) {
					TToast.show(AboutUsActivity.this,"请输入网址");
					return;
				}
				Intent intent = new Intent();
				intent.setClass(AboutUsActivity.this, BrowseActivity.class);
				intent.putExtra(Constant.URL, etWebTest.getText().toString());
				startActivity(intent);
			}
		});
		titleTextView.setText(R.string.settings_list_about_us);
		titleTextView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (System.currentTimeMillis()-clickTime < 200) {
					clickCount++;
				}else{
					clickCount = 0;
				}
				clickTime = System.currentTimeMillis();
				if (clickCount > 10) {
					clickCount = 0;
					if (layWebTest.getVisibility() == View.VISIBLE) {
						DiaoBaoSharedPreferences.setSharedPreferencesValueToBoolean("WEB_TEST_KEY", false, AboutUsActivity.this);
						layWebTest.setVisibility(View.GONE);
					}else{
						DiaoBaoSharedPreferences.setSharedPreferencesValueToBoolean("WEB_TEST_KEY", true, AboutUsActivity.this);
						layWebTest.setVisibility(View.VISIBLE);
					}
				}
			}
		});

		TextPaint paint;

		mOfficeHeaderTextView = (TextView) findViewById(R.id.tv_about_us_office_website_header);
		mOfficeHeaderTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Toast.makeText(getApplicationContext(), "ssdd",
				// Toast.LENGTH_SHORT).show();
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri
						.parse(getString(R.string.about_us_office_website_content)));
				startActivity(intent);
			}
		});

		paint = mOfficeHeaderTextView.getPaint();
		paint.setFakeBoldText(true);

		mOfficeContentTextView = (TextView) findViewById(R.id.tv_about_us_office_website_content);
		mOfficeContentTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri
						.parse(getString(R.string.about_us_office_website_content)));
				startActivity(intent);
			}
		});

		mWeChatHeaderTextView = (TextView) findViewById(R.id.tv_about_us_wechat_header);
		paint = mWeChatHeaderTextView.getPaint();
		paint.setFakeBoldText(true);

		mWeChatHeaderTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri
						.parse("http://weixin.qq.com/r/JXUcBHLE6S_WrTZn9yA3"));
				startActivity(intent);
			}
		});

		mLlWeb = findViewById(R.id.ll_web);
		mLlWeb.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri
						.parse("https://beian.miit.gov.cn/#/Integrated/recordQuery"));
				startActivity(intent);
			}
		});
		mWeChatContentTextView = (TextView) findViewById(R.id.tv_about_us_wechat_content);

		mWeChatContentTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri
						.parse("http://weixin.qq.com/r/JXUcBHLE6S_WrTZn9yA3"));
				startActivity(intent);
			}
		});

		mWeiBoHeaderTextView = (TextView) findViewById(R.id.tv_about_us_weibo_header);
		paint = mWeiBoHeaderTextView.getPaint();
		paint.setFakeBoldText(true);

		mWeiBoHeaderTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri.parse(getResources().getString(R.string.about_us_weibo_url)));
				startActivity(intent);
			}
		});

		mWeiBoContentTextView = (TextView) findViewById(R.id.tv_about_us_weibo_content);
		mWeiBoContentTextView_two = (TextView) findViewById(R.id.tv_about_us_weibo_content_02);
		mWeiBoContentTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri.parse(getResources().getString(R.string.about_us_weibo_url)));
				startActivity(intent);
			}
		});
		mWeiBoContentTextView_two.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri.parse(getResources().getString(R.string.about_us_weibo_url)));
				startActivity(intent);
			}
		});

		mPhoneHeaderTextView = (TextView) findViewById(R.id.tv_about_us_phone_header);
		paint = mPhoneHeaderTextView.getPaint();
		paint.setFakeBoldText(true);

		mPhoneContentTextView = (TextView) findViewById(R.id.tv_about_us_phone_content);

		mPhoneContentTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			}
		});

		mEmailHeaderTextView = (TextView) findViewById(R.id.tv_about_us_email_header);
		paint = mEmailHeaderTextView.getPaint();
		paint.setFakeBoldText(true);

		mEmailHeaderTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					Intent intent = new Intent(Intent.ACTION_SENDTO);
					intent.setData(Uri.parse("mailto:wemedia@sharereader.cn"));
					intent.putExtra(Intent.EXTRA_SUBJECT,
							getString(R.string.sub_settings_feedback_title));
					// intent.putExtra(Intent.EXTRA_TEXT, extraText);
					startActivity(intent);

				} catch (ActivityNotFoundException e) {
					Toast.makeText(getApplicationContext(),
							R.string.info_email_start_failed, Toast.LENGTH_LONG)
							.show();
				}
			}
		});

		mEmailContentTextView = (TextView) findViewById(R.id.tv_about_us_email_content);

		mEmailContentTextView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					Intent intent = new Intent(Intent.ACTION_SENDTO);
					intent.setData(Uri.parse("mailto:fu@doufu.la"));
					intent.putExtra(Intent.EXTRA_SUBJECT,
							getString(R.string.sub_settings_feedback_title));
					// intent.putExtra(Intent.EXTRA_TEXT, extraText);
					startActivity(intent);

				} catch (ActivityNotFoundException e) {
					Toast.makeText(getApplicationContext(),
							R.string.info_email_start_failed, Toast.LENGTH_LONG)
							.show();
				}
			}
		});
	TextView versonHead = (TextView) findViewById(R.id.tv_about_us_version_header);
	paint = versonHead.getPaint();
	paint.setFakeBoldText(true);
	TextView tvVersionName=(TextView)findViewById(R.id.tv_about_us_version_code);
	PackageInfo packInfo;
	try {
		packInfo = getPackageManager().getPackageInfo(
					getPackageName(), 0);
		String version = packInfo.versionName;
		tvVersionName.setText("Androidv"+version);
	} catch (NameNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}

	public void back(View view) {
		onBackPressed();
	}

 

}
